<?php
namespace app\common\model;

class PlatformAccount extends Base
{
    protected $table = 'platform_accounts';

    protected static function init()
    {

    }

    public function getCreateTimeLabelAttr($value, $data)
    {
        if (empty($data['create_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['create_time']);
    }

    public function getUpdateTimeLabelAttr($value, $data)
    {
        if (empty($data['update_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['update_time']);
    }

    public function getLastLoginIpLabelAttr($value, $data)
    {
        if (!empty($data['last_login_ip'])) {
            return long2ip(intval($data['last_login_ip']));
        }

        return '';
    }

    public function getLastLoginTimeLabelAttr($value, $data)
    {
        if (!empty($data['last_login_time'])) {
            return date('Y-m-d H:i:s', $data['last_login_time']);
        }

        return '';
    }

    public function getRoleIdsAttr($value, $data)
    {
        $temp = ManagerRole::where('manager_id','=', $data['id'])->where('module_name', '=', 'platform')->column('role_id');

        return $temp;
    }

    public function getPlatformNameAttr($value, $data)
    {
        $platform = Platform::where('id', $data['platform_id'])->find();

        if (empty($platform)) {
            return '';
        }

        return $platform['name'];
    }
}